<?php if ($tab == 'contacts') { /*Page is contacts */ ?>  
    <div id="nav"><!-- Navigation with tabs -->
        <ul>
            <a href="<?php echo url_for('sales_index_contacts') ?>"><li class="sel"><?php echo image_tag('Icons/ic_menu_contacts.png') ?>Contacts</li></a><!-- SELECTED TAB -->
            <a href="<?php echo url_for('sales_index_orders') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_orders.png') ?>Orders</li></a>
            <a href="<?php echo url_for('sales_index_pnp') ?>"><li class="no_sel"><span style="float: left;"><?php echo image_tag('Icons/ic_menu_products_parts.png') ?></span><span style="float: left; margin: -2px 0 0 0;">Materials</span><span style=" float: left; margin-top: -5px;">&amp; Products</span></li></a>
            <a href="<?php echo url_for('purchase_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_purchase.png') ?>Purchase</li></a>
            <a href="<?php echo url_for('stock_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_stock.png') ?>Stock</li></a>
            <?php if($sf_user->isSuperAdmin()){ ?>
            <a href="<?php echo url_for('admin_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_stock.png') ?>Admin</li></a>
            <?php } ?>
        </ul>
        
    </div> <!-- end navigation -->
    <div id="page"> <!-- The page -->
        <?php
        //include _contacts.php and the pager
        include_partial('contacts', array('contacts' => $pagerContacts->getResults(), 'filter' => $filter)); //includes _contacts.php
        include_partial('pagerMultiple', array('pager' => $pagerContacts, 'url' => 'sales_filter_contacts', 'kind' => 'contact', 'previousKind' => 'orderscontact', 'previousPager' => $pagerOrdersContact));
        //When clicking on a contact it shows information of that contact at below the list of contacs
        //There are three options there: General information of that contact/orders of that contact/notes of that contact
        if ($showContact) { //general information of contact
            ?>
            <div id="info"> 
                <div id="info_nav"><!-- the navigation tabs -->
                    <ul>
                        <a href="<?php echo url_for('sales_show_contact', $contact) ?>"><li class="sel"><?php echo image_tag('Icons/ic_info_general.png') ?>General</li></a> <!-- SELECTED TAB -->
                        <a href="<?php echo url_for('sales_show_orders_contact', $contact) ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_info_orders.png') ?>Orders</li></a>
                        <a href="<?php echo url_for('sales_show_note_contact', $contact) ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_info_notes.png') ?>Note</li></a>
                    </ul>
                </div>
                <!-- The partial _contactInfo with the general information of the contact -->
                <?php include_partial('contactInfo', array('contact' => $contact)); ?>
            </div>
            <?php
        } elseif ($showOrdersContact) { /*list of orders of that contact*/ ?>
                <div id="info">   
                    <div id="info_nav"><!-- the navigation tabs -->
                        <ul>
                            <a href="<?php echo url_for('sales_show_contact', $contact) ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_info_general.png') ?>General</li></a>
                            <a href="<?php echo url_for('sales_show_orders_contact', $contact) ?>"><li class="sel"><?php echo image_tag('Icons/ic_info_orders.png') ?>Orders</li></a><!-- SELECTED TAB -->
                            <a href="<?php echo url_for('sales_show_note_contact', $contact) ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_info_notes.png') ?>Note</li></a>
                        </ul>
                    </div>
                    <!-- The partial _contactOrders with the all the orders of selected contact -->
                    <?php include_partial('contactOrders', array('contact' => $contact, 'ordersContact' => $pagerOrdersContact->getResults(), 'pagerOrdersContact' => $pagerOrdersContact, 'pagerContacts' => $pagerContacts)); ?>
                </div>
            <?php
        } elseif ($showNote) { /*notes of that contact*/ ?>
                <div id="info">      
                   <div id="info_nav"><!-- the navigation tabs -->
                        <ul>
                            <a href="<?php echo url_for('sales_show_contact', $contact) ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_info_general.png') ?>General</li></a>
                            <a href="<?php echo url_for('sales_show_orders_contact', $contact) ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_info_orders.png') ?>Orders</li></a>
                            <a href="<?php echo url_for('sales_show_note_contact', $contact) ?>"><li class="sel"><?php echo image_tag('Icons/ic_info_notes.png') ?>Note</li></a><!-- SELECTED TAB -->
                        </ul>
                   </div>
                   <!-- The partial _contactsNotes with the notes of selected contact -->
                   <?php include_partial('contactNotes', array('contact' => $contact)); ?>
                </div>
        <?php } ?>
    </div><!-- close the page -->
<?php
} //close if tab is contacts
if ($tab == 'orders' || $tab == 'return') { /* Page is orders */ ?>
    <div id="nav"><!-- Navigation -->
        <ul>
            <a href="<?php echo url_for('sales_index_contacts') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_contacts.png') ?>Contacts</li></a>
            <a href="<?php echo url_for('sales_index_orders') ?>"><li class="sel"><?php echo image_tag('Icons/ic_menu_orders.png') ?>Orders</li></a> <!-- SELECTED TAB -->
            <a href="<?php echo url_for('sales_index_pnp') ?>"><li class="no_sel"><span style="float: left;"><?php echo image_tag('Icons/ic_menu_products_parts.png') ?></span><span style="float: left; margin: -2px 0 0 0;">Materials</span><span style=" float: left; margin-top: -5px;">&amp; Products</span></li></a>
            <a href="<?php echo url_for('purchase_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_purchase.png') ?>Purchase</li></a>
            <a href="<?php echo url_for('stock_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_stock.png') ?>Stock</li></a>
            <?php if($sf_user->isSuperAdmin()){ ?>
            <a href="<?php echo url_for('admin_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_stock.png') ?>Admin</li></a>
            <?php } ?>
        </ul>
    </div><!-- End navigation -->
    <div id="page"><!-- The page -->
        <?php
        include_partial('orders', array('orders' => $pagerOrders->getResults(), 'filter' => $filter));
        include_partial('pagerMultiple', array('pager' => $pagerOrders, 'url' => url_for('sales_index_orders'), 'kind' => 'order', 'previousKind' => 'orderinfo', 'previousPager' => $pagerItems));
        if ($showOrder) { /* The information of the selected order */ ?>
            <div id="info">
                <div id="info_nav"><!-- the navigation tabs -->
                    <ul>
                        <a href="<?php echo url_for('sales_show_order', $order) ?>"><li class="sel"><?php echo image_tag('Icons/ic_info_orders.png') ?>General</li></a><!-- SELECTED TAB -->
                        <a href="<?php echo url_for('sales_show_materials_order', $order) ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_material.png') ?>Material</li></a>
                    </ul>
                </div>
                <!-- The partial _orderInfo to see what was on the selected order -->
                <?php include_partial('orderInfo', array('order' => $order, 'items' => $pagerItems->getResults(), 'pagerItems' => $pagerItems, 'pagerOrders' => $pagerOrders)); ?>
            </div>
        <?php } elseif ($showMaterialsOrder) { /* What materials is used for the selected order */?>
            <div id="info">
                <div id="info_nav"><!-- the navigation tabs -->
                    <ul>
                        <a href="<?php echo url_for('sales_show_order', $order) ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_info_orders.png') ?>General</li></a>
                        <a href="<?php echo url_for('sales_show_materials_order', $order) ?>"><li class="sel"><?php echo image_tag('Icons/ic_material.png') ?>Material</li></a><!-- SELECTED TAB -->
                    </ul>
                </div>
                <!-- The partial _orderMaterials to see what is used compared to what should be used -->
                <?php include_partial('orderMaterials', array('order'=> $order, 'materials' => $pagerMaterials->getResults(), 'pagerMaterials' => $pagerMaterials)); ?>
            </div>
        <?php } ?>
    </div><!-- close page -->
<?php
} //close if tab is orders or return
if ($tab == 'pnp' || $tab == 'products' || $tab == 'parts') { /* the pages parts and material, products and material */ ?>
    <div id="nav"><!-- The navigation -->
        <ul>
            <a href="<?php echo url_for('sales_index_contacts') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_contacts.png') ?>Contacts</li></a>
            <a href="<?php echo url_for('sales_index_orders') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_orders.png') ?>Orders</li></a>
            <a href="<?php echo url_for('sales_index_pnp') ?>"><li class="sel"><span style="float: left;"><?php echo image_tag('Icons/ic_menu_products_parts.png') ?></span><span style="float: left; margin: -2px 0 0 0;">Materials</span><span style=" float: left; margin-top: -5px;">&amp; Products</span></li></a><!-- SELECTED TAB -->
            <a href="<?php echo url_for('purchase_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_purchase.png') ?>Purchase</li></a>
            <a href="<?php echo url_for('stock_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_stock.png') ?>Stock</li></a>
            <?php if($sf_user->isSuperAdmin()){ ?>
            <a href="<?php echo url_for('admin_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_stock.png') ?>Admin</li></a>
            <?php } ?>
        </ul>
    </div>
    <div id="page"><!-- the page -->
        <div id="par_header"><!-- header with buttons and search -->
            <div id="bt_area">
                <div class="button">
                    <a href="<?php echo url_for('sales_new_part') ?>">
                        <img src="<?php echo image_path('Buttons/bt_add_par.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_add_par_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_add_par.png') ?>';" title="Add new material"/>
                    </a>
                </div>
                <div class="button">
                    <a href="<?php echo url_for('sales_new_product') ?>">
                    <img src="<?php echo image_path('Buttons/bt_add_prod.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_add_prod_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_add_prod.png') ?>';" title="Add new product"/>
                    </a>
                </div>
                <div class="button"><!-- create price list button -->
                    <a href="<?php echo url_for('sales/createPriceList') ?>">
                        <img src="<?php echo image_path('Buttons/bt_sales.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_sales_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_sales.png') ?>';" title="Create price list"/>
                    </a>
                </div>
            </div>
            <div id="search"><!-- Search option for materials -->
                <?php echo form_tag('sales_filter_pnp') ?>
                <fieldset>
                    <table>
                        <legend class="bold">Search Materials</legend>
                        <tr>
                            <td>Material No.</td>
                            <td class="input_small"><?php echo $filterParts['part_number']->render() ?></td>
                        </tr>
                        <?php echo $filterParts['name']->renderRow() ?>
                        <?php echo $filterParts['type']->renderRow() ?>
                        <tr><td><input type="submit" value="" name="submit_filter" class="bt_search" title="Search material"/></td></tr>
                    </table>
                    <div id="del_list">
                        <a href="<?php echo url_for('sales_index_pnp') ?>">
                            <img src="<?php echo image_path('Buttons/bt_cancel_small.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_cancel_small_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_cancel_small.png') ?>';" width="55px" title="Back to complete material list"/>
                        </a>
                    </div>
                    <span id="tooltip1"><a href=""><img src="<?php echo image_path('Buttons/bt_help.png') ?>" /><span>Fill in one or more field(s) to search material</span></a></span>
                </fieldset>  
            </div><!-- end search -->
            <div id="search2"><!-- seard for products -->
                <?php echo form_tag('sales_filter_pnp') ?>
                <fieldset>
                    <table>
                        <legend class="bold">Search Product</legend>
                        <tr>
                            <td>Product No.</td>
                            <td class="input_small"><?php echo $filterProducts['product_number']->render() ?></td>
                        </tr>
                        <?php echo $filterProducts['name']->renderRow() ?>
                        <?php echo $filterProducts['type']->renderRow() ?>
                        <tr><td><input type="submit" value="" name="submit_filter" class="bt_search" title="Search product"/></td></tr>
                    </table>
                    <div id="del_list">
                        <a href="<?php echo url_for('sales_index_pnp') ?>">
                            <img src="<?php echo image_path('Buttons/bt_cancel_small.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_cancel_small_hov.png') ?>';" onmouseout="this.src='<?php echo image_path('Buttons/bt_cancel_small.png') ?>';" width="55px" title="Back to complete product list"/>
                        </a>
                    </div>
                    <span id="tooltip2"><a href=""><img src="<?php echo image_path('Buttons/bt_help.png') ?>" /><span>Fill in one or more field(s) to search products</span></a></span>
                </fieldset>   
            </div>
        </div><!-- End header -->
        
        <div id="prod_par"><!-- the two tables with the lists of materials and products --> 
            <h2>Materials</h2>
            <?php
            include_partial('parts', array('parts' => $pagerParts->getResults())); //material table
            include_partial('pagerMultiple', array('pager' => $pagerParts, 'url' => 'sales_index_pnp', 'kind' => 'part', 'previousKind' => 'product', 'previousPager' => $pagerProducts));           
            ?>
            <h2>Products</h2>
            <?php
            include_partial('products', array('products' => $pagerProducts->getResults())); //product table
            include_partial('pagerMultiple', array('pager' => $pagerProducts, 'url' => 'sales_index_pnp', 'kind' => 'product', 'previousKind' => 'part', 'previousPager' => $pagerParts));
            ?>
        </div>
    </div><!-- close page -->
<?php } ?>